from google.appengine.ext import db
from Common.CompanyOrg import Company
from Common.DuplicatedInstanceError import DuplicatedInstanceError

class QuestionFormTemplate(db.Model):
    """
    Parent is company
    """
    TemplateFrameName = db.StringProperty(required=True)
    TemplateHeight = db.IntegerProperty(required=True)
    TemplateMetaHtml = db.TextProperty(required=True)
    
    Ref_Company = db.ReferenceProperty(Company, collection_name='QuestionFormTemplates')
    
    #
    # To-Do: here add reference to DW created property class
    #
    
    def put (self):
        # Make sure e-mails are unique for each user
        if (not self.is_saved()) and QuestionFormTemplate.get_by_key_name(self.TemplateFrameName, self._parent_key):
            raise DuplicatedInstanceError ('QuestionFormTemplate.FrameName', self.TemplateFrameName)

        db.Model.put (self)
        
    def TransactionPut(self):
        db.run_in_transaction(self.put)